package com.hadwinling.socket;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author HadwinLing
 * @version V1.0
 * @Package com.hadwinling.socket
 * @date 2020/11/14 10:26
 */
public class ServerTCP {
    public static void main(String[] args) {

        try(ServerSocket serverSocket=new ServerSocket(8888)) {
            System.out.println("服务器启动,等待连接。。。。。");
            //等待客户端连接
            Socket socket=serverSocket.accept();
            //从套接字中获取输入流
            InputStream is=socket.getInputStream();
            //读取数据
            byte[] b=new byte[1024];
            int len=is.read(b);
            System.out.println("客户端说："+new String(b,0,len));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
